//
//  AppDelegate.m
//  MyDoctor
//
//  Created by 黑眼圈 on 16/5/4.
//  Copyright © 2016年 heiyan. All rights reserved.
//

#import "AppDelegate.h"
#import "HZMainViewController.h"
#import "HZDrawerViewController.h"
#import "MMDrawerController.h"


@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    //设置抽屉控制器为主窗口的根控制器
    [self setupRootView];
    
    //设置外观对象
    [self setupAppearance];
    
    return YES;
}


#pragma mark -
#pragma mark    设置抽屉控制器为主窗口的根控制器
-(void)setupRootView{
    
    //创建 window
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    
    
    //初始化中心视图
    HZMainViewController* mainVc = [[HZMainViewController alloc]init];
    
    //初始化左视图
    HZDrawerViewController* leftVc = [[HZDrawerViewController alloc]init];
    
    
    //创建抽屉控制器
    MMDrawerController* drawerVc = [[MMDrawerController alloc]initWithCenterViewController:[[UINavigationController alloc]initWithRootViewController:mainVc] leftDrawerViewController:leftVc];
    
    //设置抽屉的宽度
    drawerVc.maximumLeftDrawerWidth = 280;
    
    //添加打开和关闭抽屉视图的手势
    [drawerVc setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
    [drawerVc setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
    

    
    //设置抽屉为主窗口的根视图
    self.window.rootViewController = drawerVc;

    
    //设置为主窗口并可见
    [self.window makeKeyAndVisible];
    
    
}


#pragma mark -
#pragma mark    设置外观对象
-(void)setupAppearance{
    
    //创建导航栏的外观对象
    UINavigationBar* bar = [UINavigationBar appearance];
    
    //设置导航栏的背景色
    [bar setBackgroundImage:[UIImage imageNamed:@"nav"] forBarMetrics:UIBarMetricsDefault];

    //设置导航栏中间文本的颜色
    bar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor grayColor]};
    
    //设置导航栏按钮字体的颜色
    bar.tintColor = [UIColor whiteColor];
    

}



- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
